﻿using System;
using System.Xml;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;

namespace InfoJetSoft.Service.Worker
{
	
	class XSNViewFormatHTMLWorker
	{
		
		public static void  formatHTML(View view)
		{
			XmlElement root = view.Doc.DocumentElement;
			XmlElement htmlElement = (XmlElement) DOMUtil.selectOneNode(root, "//html", view.NsResolver);
			XmlElement headElement = (XmlElement) DOMUtil.selectOneNode(root, "//html/head", view.NsResolver);
			XmlElement bodyElement = (XmlElement) DOMUtil.selectOneNode(root, "//html/body", view.NsResolver);
			
			htmlElement = DOMUtil.renameElementName( htmlElement , "div" );
			htmlElement.SetAttribute("id", JetConstant.DocId);
			htmlElement.SetAttribute("class", "xdoc");
			
			headElement = DOMUtil.renameElementName( headElement , "div" );
			headElement.SetAttribute("id", JetConstant.StyleId);
			headElement.SetAttribute("style", "display:none;");
			
			bodyElement = DOMUtil.renameElementName( bodyElement , "div" );
			bodyElement.SetAttribute("id", "{./@" + JetConstant.JetId + "}");
			
			XmlElement viewElement = view.Doc.CreateElement("div");
			viewElement.SetAttribute("id", JetConstant.ViewId);
			//CID 0425 //2009.10.16 //Begin
			if( view.ViewWidth != null )
			{
				viewElement.SetAttribute("style", "width:" + view.ViewWidth + ";");
			}
			//CID 0425 //2009.10.16 //End

			htmlElement.RemoveChild(bodyElement);
			viewElement.AppendChild(bodyElement);
			htmlElement.AppendChild(viewElement);
		}
	}
}